﻿using System.Drawing;
using System.Drawing.Drawing2D;
using CanvasControl.View;
using GraphDrawing.Graph.Model;

namespace GraphDrawing.Graph.View
{
    public class LinkingView : ILinkingView
    {
        readonly LineAppearance appearance;

        public LinkingView(LineAppearance appearance)
        {
            this.appearance = appearance;
        }

        public void Draw(DrawingContext dc, LineShapeType type, Point start, Point end)
        {
            var cookie = dc.Graphics.BeginContainer();
            try
            {
                dc.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
                dc.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                using (var pen = appearance.CreatePen())
                {
                    var path = GraphicsPathFactory.CreatePath(type, start, end);
                    dc.Graphics.DrawPath(pen, path);
                }
            }
            finally
            {
                dc.Graphics.EndContainer(cookie);
            }
        }
    }
}